package com.lukebang.controller;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.lukebang.service.IGoodService;
import com.sun.tools.internal.ws.processor.model.Model;

/**
 * 
 * GoodController 上午10:38:57
 * 
 * Copyright zhaocj Inc. All rights reserved. Love ME Like Justin Bieber.
 */
@Controller
@RequestMapping("/good")
public class GoodController {
	private static Logger logger = LogManager.getLogger(GoodController.class.getName());
	@Resource
	private IGoodService goodService;

	/**
	 * 根据订单查询该订单的成品帘信息
	 * 
	 * @param offset
	 * @param limit
	 * @param sort
	 * @param order
	 * @param indentID
	 * @param session
	 * @return
	 */
	@RequestMapping("/queryIndentProductGoodPartsByIndent")
	public @ResponseBody Map<String, Object> queryIndentProductGoodPartsByIndent(Integer offset, Integer limit,
			String sort, String order, Integer indentID, HttpSession session) {
		logger.debug("传入的参数对象是{},{},{},{},{}", offset, limit, sort, order, indentID);
		Map<String, Object> retMap = null;
		try {
			retMap = goodService.selectIndentProductGoodPartsByIndent(offset, limit, sort, order, indentID, session);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return retMap;
	}

	/**
	 * 根据订单查询该订单的布艺帘信息
	 * 
	 * @param offset
	 * @param limit
	 * @param sort
	 * @param order
	 * @param indentID
	 * @param session
	 * @return
	 */
	@RequestMapping("/queryIndentClothGoodPartsByIndent")
	public @ResponseBody Map<String, Object> queryIndentClothGoodPartsByIndent(Integer offset, Integer limit,
			String sort, String order, Integer indentID, HttpSession session) {
		logger.debug("传入的参数对象是{},{},{},{},{}", offset, limit, sort, order, indentID);
		Map<String, Object> retMap = null;
		try {
			retMap = goodService.selectIndentClothGoodPartsByIndent(offset, limit, sort, order, indentID, session);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return retMap;
	}

	/**
	 * 根据订单ID查询该订单的商品信息 还有商品的尺寸信息
	 * 
	 * @param indentID
	 * @return
	 */
	@RequestMapping("/queryIndentGoodPartsByIndent")
	public @ResponseBody Map<String, Object> queryIndentGoodPartsByIndent(Integer indentID) {
		Map<String, Object> retMap = null;
		try {
			retMap = goodService.queryIndentGoodPartsByIndent(indentID);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return retMap;
	}

	/**
	 * 从redis中获取到订单的商品和尺寸信息
	 * 
	 * @param fakeIndentID
	 * @param cityCodeStr
	 * @return
	 */
	@RequestMapping("/refreshInstallIndentGoods")
	public @ResponseBody Map<String, Object> refreshInstallIndentGoods(String fakeIndentID, String cityCodeStr) {
		logger.debug("要查询的fakeIdent商品的ID:{}", fakeIndentID);
		logger.debug("cityCodeStr:{}", cityCodeStr);
		Map<String, Object> retMap = null;
		try {
			retMap = goodService.selectForRefreshInstallIndentGoods(fakeIndentID, cityCodeStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return retMap;
	}

	/**
	 * 根据订单号查询安装订单的商品和尺寸信息
	 * 
	 * @param indentID
	 * @return
	 */
	@RequestMapping("/queryInstallIndentGood")
	public @ResponseBody Map<String, Object> queryInstallIndentGoodByIndentID(String indentID,org.springframework.ui.Model model) {
		logger.debug("要查询商品的订单ID:{}", indentID);
		Map<String, Object> retMap = null;
		try {
			retMap = goodService.selectInstallIndentGoodByIndentID(indentID);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("查询商品信息："+indentID);
		System.out.println(retMap);
		model.addAttribute("retMap", retMap);
		return retMap;
	}

}
